<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
class M_user_tool_tip extends MY_Model {
	
	protected $_table = "user_help_tip";
	protected $_uid = "id";

	public function __construct(){
		parent::__construct();
	}

	public function get_user_profile()
	{
		$user_id = $this->c_user->userid;
		$sy = $this->_get_user_profile($user_id);
		
		if($sy === false){

			/** IF RECORD DO NOT EXIST CREATE RECORD FIRST BASED ON THE SYSTEM CURRENT SCHOOL YEAR **/	
			unset($data);
			$data['user_id'] = $user_id;
			if($user_id){
				$xrs_add = $this->insert($data); //Insert data
				if($xrs_add){
					return $this->_get_user_profile($user_id); //return add record
				}
			}
			
		}

		return $sy;
	}	

	private function _get_user_profile($user_id)
	{
		return $this->pull(array('user_id' => $user_id));
	}

	public function set_user_tool_tip()
	{
		$ct = $this->M_user_tool_tip->get_user_profile($this->c_user->userid);
		unset($data);
		if($ct->help_tip=='yes'){
			$data['help_tip'] = 'no';
		}else{
			$data['help_tip'] = 'yes';
		}
		$rs = $this->update(array('user_id' => $this->c_user->userid), $data);
		return $rs;
	}
	
	public function get_tool_tip($user_id=FALSE)
	{
		if($user_id)
		{
			$tip = $this->db->select('help_tip')
							->where('user_id',$user_id)
							->get('user_help_tip');
			return $tip->num_rows() >= 1 ? $tip->row():"";
		}
	}
}